/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: zhnb
 * Date: 2011-8-9 上午10:59:09
 */
package box;

import java.io.Serializable;
import java.util.Scanner;

import Ice.Application;
import echo.MyechoPrx;
import echo.MyechoPrxHelper;

public class MyechoClient extends Application implements Serializable {

    private static final long serialVersionUID = -5936493693635168567L;

    @Override
    public int run(String[] args) {
        
        // 如果有没有被接收处理的参数，则参数长度大于0，判断为错误。
        if (args.length > 0) {
            System.err.println(appName() + ": too many(or illegal) arguments");
            return 1;
        }
        
        // 获取代理
        MyechoPrx myechoPrx = MyechoPrxHelper.uncheckedCast(communicator().
                propertyToProxy("Hello.Proxy"));
        
        // 如果代理为空，则获取失败
        if (myechoPrx == null) {
            System.err.println(appName() + ": To obtain proxy faild. May cause by Hello.Proxy missing.");
            return 1;
        }
        
        // 执行操作
        Scanner scIn = new Scanner(System.in);
        do {
            System.out.println("Please input a test string('-q' to quit): ");
            myechoPrx.doEcho(scIn.next());
        } while (!scIn.equals("-q"));
        
        return 0;
    }
    
    public static void main(String[] args) {

        MyechoClient myechoClient = new MyechoClient();
        int status = myechoClient.main("Client", args, "config.client");
        System.exit(status);
        
    }

}
